import { http } from "@/utils/http";
import type { AxiosResultDefault } from "../type";

// 1、查看证照分类
export const viewCertificateCategoryAPI = data => {
  return http.request("post", "/dms/api/v1/license/viewLicenceCategory", {
    data
  });
};

// 2、更新证照分类
export const updateCertificateCategoryAPI = data => {
  return http.request("post", "/dms/api/v1/license/updateLicenceCategory", {
    data
  });
};

// 3、删除证照分类
export const deleteCertificateCategoryAPI = data => {
  return http.request("post", "/dms/api/v1/license/delLicenceCategory", {
    data
  });
};

// 4、获取证照分类列表
export const getCategoryListAPI = data => {
  return http.request("post", "/dms/api/v1/license/listLicenceCategory", {
    data
  });
};

// 5、获取证照列表
export const getCertificateListAPI = data => {
  return http.request("post", "/dms/api/v1/license/listLicence", {
    data
  });
};

// 6、更新证照列表
export const saveCertificateAPI = data => {
  return http.request("post", "/dms/api/v1/license/updateLicence", {
    data
  });
};

// 7、删除证照
export const deleteCertificateAPI = data => {
  return http.request("post", "/dms/api/v1/license/delLicence", {
    data
  });
};

// 8、改变证照状态
export const changeCertificateStatusAPI = data => {
  return http.request("post", "/dms/api/v1/license/changeLicenceState", {
    data
  });
};

// 9、注销证照
export const logOffCertificateAPI = data => {
  return http.request("post", "/dms/api/v1/license/cancelLicence", {
    data
  });
};

// 10、更新证照提醒
export const saveCertificateNoticeAPI = data => {
  return http.request("post", "/dms/api/v1/license/updateLicenceMessageConfig", {
    data
  });
};

// 11、查看证照提醒
export const getCertificateNoticeAPI = data => {
  return http.request("post", "/dms/api/v1/license/detailLicenceMessageConfig", {
    data
  });
};

// 12、上传证照
export const uploadAPI = data => {
  return http.request(
    "post",
    "/dms/api/v1/license/uploadLicense",
    {
      data
    },
    {
      headers: {
        noLoading: true,
        "content-type": "application/x-www-form-urlencoded"
      }
    }
  );
};

// 13、证照编辑查询
export const editSearchAPI = data => {
  return http.request("post", "/dms/api/v1/license/viewLicenceBase", {
    data
  });
};

// 证照消息提醒开关
export const changeRemindStatusAPI = data => {
  return http.request("post", "/dms/api/v1/license/updateSwitchFlag", {
    data
  });
};

// 获取设备编码和名称
export const getEqpListAPI = data => {
  return http.request("post", "/digitaltwins/api/v1/publish/equipment/queryListByEqpIds", {
    data
  });
};

// 证照名称下拉框
export const licenseNameSelectsAPI = data => {
  return http.request("post", "/dms/api/v1/license/licenseNameSelects", {
    data
  });
};

// 更新证照名称
export const updateLicenceNameAPI = data => {
  return http.request("post", "/dms/api/v1/license/updateLicenceName", {
    data
  });
};

// 删除证照名称
export const delLicenceNameAPI = data => {
  return http.request("post", "/dms/api/v1/license/delLicenceName", {
    data
  });
};

// 批量删除证照
export const batchDelLicenceAPI = data => {
  return http.request("post", "/dms/api/v1/license/batchDelLicence", {
    data
  });
};

/**
 * 后端重构用的接口
 */

// 创建树形结构中的某一级
export const setCreateTreeAPI = data => {
  return http.request("post", "/dms/api/v1/certificate/create", {
    data
  });
};

// 获取证照分类、证照名称的数据源
export const getSelectListAPI = data => {
  return http.request("post", "/dms/api/v1/certificate/getSelectList", {
    data
  });
};

// 获取树形结构的数据
export const getTreeAPI = params => {
  return http.request("get", "/dms/api/v1/certificate/getTree", {
    params
  });
};

// 更新树形结构的数据
export const updateTreeAPI = data => {
  return http.request("post", "/dms/api/v1/certificate/update", {
    data
  });
};

// 删除树形结构中的某一级
export const deleteTreeAPI = params => {
  return http.request("delete", `/dms/api/v1/certificate/delete?id=${params}`);
};

// 证照台账列表
// 创建证照
export const certificateInfoCreateAPI = data => {
  return http.request("post", "/dms/api/v1/certificateInfo/create", {
    data
  });
};

// 删除证照
export const deleteCertificateInfoAPI = params => {
  return http.request("delete", `/dms/api/v1/certificateInfo/delete?id=${params}`);
};

// 证照查询列表
export const certificateInfoListAPI = data => {
  return http.request("post", "/dms/api/v1/certificateInfo/pageCertificateInfo", {
    data
  });
};

// 更新证照
export const updateCertificateInfoListAPI = data => {
  return http.request("post", "/dms/api/v1/certificateInfo/update", {
    data
  });
};

// 导入证照台账
export const importDataAPI = data => {
  return http.request(
    "post",
    "/dms/api/v1/certificateInfo/importData",
    {
      data
    },
    {
      headers: {
        noLoading: true,
        "content-type": "application/x-www-form-urlencoded"
      }
    }
  );
};

type ResPic = {
  id?: String;
  originalName?: String;
  fileName?: String;
  fileType?: String; //文件类型：JPG/DOC/EXCEL 等	string
  fileSize?: Number; //	文件大小，单位：K	integer(int32)
  fileUrl: String; //	文件URL	string
  moduleName: String; //	所属模块名称：PROCESS/ENERGY/DIGITALTWINS 等	string
  moduleId?: Number; //	所属模块的记录ID	integer(int64)
  accountId?: Number; //	所属用户ID	integer(int64)
  accountName?: String; //所属用户名称	string
  status?: String; //	记录状态：VALID - 有效；INVALID - 无效	string
  createTime?: String; //string(date-time)
  updateTime?: String;
  pic?: Array<any>;
  originNameList?: Array<String>;
};
export const queryFileList = (data?: object) => {
  return http.request<ResPic | Array<any>>("post", "/sharing/api/v1/file/query", { data });
};

// 删除证照 批量 （证照台账）
export const delCertificateBatch = (data?: object | undefined, cb?: (err: any) => any) =>
  http.request<AxiosResultDefault>("delete", `/dms/api/v1/certificateInfo/deleteBatch`, { data }, { headers: { noLoading: true } }, cb);
